home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Programming
/
Programming Languages
/
XLisp 2.1e3
/
Sources
/
macstuff.c
< prev
next >
Wrap
Text File
|
1993-11-13
|
3KB
|
111 lines
/* macstuff.c - macintosh interface routines for xlisp */
/* Written by Brian Kendig. */
/* This file contains the stuff that the other xlisp files call directly. */
#include <stdio.h>
#include <QuickDraw.h> /* for Random */
#include <Memory.h> /* for DisposPtr */
#include <SegLoad.h> /* for ExitToShell */
#include "xlisp.h"
#define DELETE 0x08
/* externals */
extern FILE *tfp; /* transcript file pointer */
extern int cursorPos;
extern char *macgets (void);
/* local variables */
static char *linebuf = NULL, *lineptr;
static int numChars;
int lposition;
int isascii (char c) { return 1; } /* every char is an ascii char, isn't it? */
void osinit (char *banner) {
int i;
char version[] = "\nMacintosh interface by Brian Kendig.\n";
InitMac (); /* initialize the mac interface routines */
lposition = 0; /* initialize the line editor */
for (i = 0; banner[i] != '\0'; i++) macputc (banner[i]);
for (i = 0; version[i] != '\0'; i++) macputc (version[i]);
}
/* osrand - return next random number in sequence */
long osrand (long rseed) {
long k1;
/* make sure we don't get stuck at zero */
if (rseed == 0L) rseed = 1L;
/* algorithm taken from Dr. Dobbs Journal, November 1985, page 91 */
k1 = rseed / 127773L;
if ((rseed = 16807L * (rseed - k1 * 127773L) - k1 * 2836L) < 0L)
rseed += 2147483647L;
/* return a random number between 0 and MAXFIX */
return rseed;
}
FILEP osaopen (char *name, char *mode) {
return fopen (name, mode);
}
FILEP osbopen (char *name, char *mode) {
char nmode[4];
strcpy (nmode, mode); strcat (nmode, "b");
return (fopen (name, nmode));
}
int osclose (FILE *fp) { return (fclose (fp)); }
int osaputc (int ch, FILE *fp) { return (putc (ch, fp)); }
int osbputc (int ch, FILE *fp) { return (putc (ch, fp)); }
int ostgetc (void) {
int i;
if (numChars <= 0) { /* get some more */
if (linebuf) DisposPtr (linebuf);
linebuf = macgets ();
i = 0;
while (linebuf[i] != '\0') i++;
numChars = i;
if (tfp) for (i = 0; i < numChars; i++) osaputc (linebuf[i], tfp);
lineptr = linebuf;
}
numChars--;
if (*lineptr == '\r') {
lineptr++;
return '\n';
} else return (*lineptr++);
}
void ostputc (int ch) {
macputc (ch);
if (tfp) osaputc (ch, tfp);
}
void osflush (void) {
lineptr = linebuf;
numChars = 0;
lposition = 0;
}
void oscheck (void) { DoEvent (); }
void oserror (char *msg) {
char line[100], *p;
sprintf (line,"error: %s\n",msg);
for (p = line; *p != '\0'; ++p) ostputc (*p);
}
void osfinish (void) {
/* dispose of everything... */
if (linebuf) DisposPtr (linebuf);
MacWrapUp ();
ExitToShell ();
}
int renamebackup (char *filename) { return 0; }